#!/bin/bash

case $1 in
        build)
	go build "callsips.go"
	echo "编译成功..."
	sleep 1
	;;
	start)
		nohup ./callsips 2>&1 >> "callsips.log" 2>&1 /dev/null &
		echo "服务已启动..."
		sleep 1
	;;
	stop)
		ps -ef | grep callsips| grep -v grep | awk '{print $2}' | xargs kill -9
		echo "服务已停止..."
		sleep 1
	;;
	reload)
		ps -ef | grep callsips| grep -v grep | awk '{print $2}' | xargs kill -9
		sleep 1
		nohup ./callsips 2>&1 >> "callsips.log" 2>&1 /dev/null &
		echo "服务已重启..."
		sleep 1
	;;
	restart)
		ps -ef | grep callsips| grep -v grep | awk '{print $2}' | xargs kill -9
		git pull
		sleep 1
		go build "callsips.go"
		sleep 1
		nohup ./callsips 2>&1 >> "callsips.log" 2>&1 /dev/null &
		echo "服务已重启..."
		sleep 1
	;;
  	push)
  	  git pull
  	  echo "更新成功..."
  	  go build "callsips.go"
      echo "编译成功..."
  	  git add .
  		git commit -m '提交'
  		git push
  		 echo "提交成功..."
  		sleep 1
  	;;
	*)
		echo "$0 {build|start|stop|restart}"
		exit 4
	;;
esac